<?php
namespace App\Http\ViewComposers;

use Illuminate\Contracts\View\View;
use Illuminate\Users\Repository as UserRepository;
use Route;

class BaseComposer
{

    /**
     * 创建一个新的属性composer.
     *
     * @param UserRepository $users
     * @return void
     */
    public function __construct()
    {
        
    }

    /**
     * 绑定数据到视图.
     *
     * @param View $view
     * @return void
     */
    public function compose(View $view)
    {
        $view->with('route_name', Route::current()->getName());
    }


    protected function getCurrentAction()
    {
        if(\Route::current()) {
            $action = \Route::current()->getActionName();

            if($action && strpos($action,'@') !== false) {
                list($class, $method) = explode('@', $action);
                $class = class_basename($class);
                return ['controller' => $class, 'method' => $method];
            } else {
                return ['controller' => '', 'method' => ''];
            }
        }
        else
            return ['controller' => '', 'method' => ''];

    }

}
